package com.ytf.test.second;

/**
 * @author: YTF
 * @date: 2024/9/6 15:59
 * @version: 1.0
 * @description: 第二章
 */
public class ChapterTwo {
    public static void main(String[] args) {
        // 创建引用 没有值直接输出会报错
        // String s;
        // System.out.println(s);

        // 创建一个引用的同时便进行初始化，正常运行
        String s = "asdf"; // String s = new String("asdf");

        System.out.println(s);

        ATypeName aTypeName = new ATypeName();
        DataOnly dataOnly = new DataOnly();
        dataOnly.i = 47;
        dataOnly.d = 1.1;
        dataOnly.b = false;
        System.out.println(dataOnly);


        System.out.println(aTypeName.storage("a"));
        System.out.println(aTypeName.flag());
        System.out.println(aTypeName.naturalLogBase());

        // 静态后共用一份储存空间 共享一个 i
        // StaticTest staticTest1 = new StaticTest();
        // StaticTest staticTest2 = new StaticTest();
        // System.out.println("StaticTest.i = " + StaticTest.i);
        // System.out.println("staticTest1.i = "+staticTest1.i);
        // System.out.println("staticTest2.i = "+staticTest2.i);
        // staticTest1.i++;
        // System.out.println("staticTest1.i++");
        // System.out.println("staticTest1.i = "+staticTest1.i);
        // System.out.println("staticTest2.i = "+staticTest2.i);
        // // 不同的类调用的也是同一个
        // IncrementTable.increment();
        // System.out.println("staticTest1.i = "+staticTest1.i);
        // System.out.println("staticTest2.i = "+staticTest2.i);

    }

}

class ATypeName {
    /* Class body goes here */

    int storage(String s) {
        return s.length() * 2;
    }

    boolean flag() {
        return true;
    }

    double naturalLogBase() {
        return 2.718;
    }

    void nothing() {
        return;
    }

    void nothing2() {
    }

}

class DataOnly {
    int i;
    double d;
    boolean b;

    @Override
    public String toString() {
        return "DataOnly{" +
                "i=" + i +
                ", d=" + d +
                ", b=" + b +
                '}';
    }
}

class StaticTest {
    static int i = 47;
}

class IncrementTable{

    static void increment() {
        StaticTest.i++;
        System.out.println("IncrementTable 类 调用 StaticTest.i++");
    }
}

